<template>
  <div class="app-container">
    <h2>{{ this.$route.query.typeName }}</h2>
    <mavon-editor v-model="value" />
    <el-button type="primary" style="margin-top: 10px" @click="sub"
      >提交编辑</el-button
    >
  </div>
</template>

<script>
import { getAttrbute, updateAttrbute } from "@/api/course";
export default {
  data() {
    return {
      value: "## 我是标题",
      form: {},
      info: {},
      cid: this.$route.query.courseId,
      type: this.$route.query.type,
    };
  },
  created() {
    this.getAttrbute();
  },
  methods: {
    getAttrbute() {
      getAttrbute({ id: this.cid }).then((res) => {
        if (this.type == 1) {
          if (res.data.background != null) {
            this.value = res.data.background;
          }
        } else if (this.type == 2) {
          if (res.data.aim != null) {
            this.value = res.data.aim;
          }
        } else {
          if (res.data.philosophy != null) {
            this.value = res.data.philosophy;
          }
        }
        this.info = res.data;
      });
    },
    sub() {
      if(this.type == 1) {
        this.form.background = this.value;
      }else if(this.type == 2){
        this.form.aim = this.value
      }else {
        this.form.philosophy = this.value
      }
      this.form.courseId = this.cid;
      this.form.id = this.info.id;
      updateAttrbute(this.form).then((res) => {
        this.$message({
          message: "修改成功",
          type: "success",
        });
        this.form.background = ""
        this.form.aim = ""
        this.form.philosophy = ""
      });
    },
  },
};
</script>

<style scoped></style>
